import { MiddlewareConsumer, Module, NestModule, RequestMethod } from '@nestjs/common';
import { MenusService } from './menus.service';
import { MenusController } from './menus.controller';
import { Menu } from './entities/menu.entity';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Role } from '../role/entities/role.entity';
import { LoggerMiddleWare } from '../../middleware/logger.middleware';
import { JwtModule } from '@nestjs/jwt';
import { JWT_CONFIG } from 'src/config/jwt.config';
import { User } from '../users/entities/user.entity';

@Module({
  imports: [TypeOrmModule.forFeature([Menu, Role, User]), JwtModule.register({ 
    secret: JWT_CONFIG.SECRET, 
    signOptions: JWT_CONFIG.SIGN_OPTIONS 
  })],
  controllers: [MenusController],
  providers: [MenusService],
})

export class MenusModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer
      .apply(LoggerMiddleWare)
      .forRoutes({
        path: 'menus',
        method: RequestMethod.POST
      })
      // .forRoutes('menus')
  }
}
